package com.zboot.zbootadmin.project.base.controller;


import com.zboot.zbootadmin.common.utils.ServiceResult;
import com.zboot.zbootadmin.project.base.command.machinery.MachineryModelListCommand;
import com.zboot.zbootadmin.project.base.entity.MachineryModel;
import com.zboot.zbootadmin.project.base.service.MachineryModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author draw
 * @since 2021-05-08
 */
@RestController
@RequestMapping("/machinery-model")
public class MachineryModelController {
@Autowired
private MachineryModelService machineryModelService;
    /**
     * 新增
     *
     * @author draw
     * @date 2021/05/08
     **/
    @RequestMapping("/insert")
    public ServiceResult insert(@RequestBody MachineryModel machineryModel) {
        machineryModelService.save(machineryModel);
        return ServiceResult.builder().message("新增成功").build();
    }

    /**
     * 刪除
     *
     * @author draw
     * @date 2021/05/08
     **/
    @RequestMapping("/delete/{id}")
    public ServiceResult delete(@PathVariable(value = "id") Long id) {
        machineryModelService.updateToDelete(id);
        return ServiceResult.builder().message("删除成功").build();
    }

    /**
     * 更新
     *
     * @author draw
     * @date 2021/05/08
     **/
    @RequestMapping("/update")
    public ServiceResult update(@RequestBody MachineryModel machineryModel) {
        machineryModelService.save(machineryModel);
        return ServiceResult.builder().message("修改成功").build();
    }

    /**
     * 查询 根据主键 id 查询
     *
     * @author zdraw
     * @date 2021/05/08
     **/
    @RequestMapping("/get/{id}")
    public ServiceResult get(@PathVariable(value = "id") Long id) {
        return ServiceResult.builder().content(machineryModelService.getById(id)).build();
    }

    /**
     * 查询 分页查询
     *
     * @author draw
     * @date 2021/05/08
     **/
    @RequestMapping("/pageList")
    public ServiceResult pageList(@RequestBody MachineryModelListCommand command) {
        return ServiceResult.builder().content(this.machineryModelService.pageList(command)).build();
    }
}

